import Vue from 'vue'
import VueRouter from 'vue-router'
import CookbookView from '@/views/cookbook/CookbookView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home/cookbook'
  },
  {
    path: '/home',
    name: 'home',
    component: () => import(/* webpackChunkName: "home" */ '@/views/HomeView.vue'),
    children: [
      {
        path: 'cookbook',
        name: 'cookbook',
        component: CookbookView
      },
      {
        path: 'menu',
        name: 'menu',
        component: () => import(/* webpackChunkName: "about" */ '@/views/MenuView.vue')
      },
      {
        path: 'more',
        name: 'more',
        component: () => import(/* webpackChunkName: "about" */ '@/views/MoreView.vue')
      },
      {
        path: 'map',
        name: 'map',
        component: () => import(/* webpackChunkName: "about" */ '@/views/MapView.vue')
      }
    ]
  },
  {
    path: "/list",
    name: 'list',
    component: () => import(/* webpackChunkName: "list" */ '@/views/ListView.vue')
  },
  {
    path: "/detail",
    name: 'detail',
    component: () => import(/* webpackChunkName: "detail" */ '@/views/DetailView.vue')
  }
]

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
